VB问题这个怎么算的`~?

来源:百度知道 编辑:UC知道 时间:2024/07/01 08:14:15
Private Sub proc1(x As Integer, y As Integer, z As Integer)
x = 3 * z
y = 2 * z
z = x + y
End Sub
Private Sub Command1_Click()
Dim x As Integer, y As Integer, z As Integer
x = 1: y = 2: z = 3
Call proc1(x, x, z)
Print x; x; z
Call proc1(x, y, y)
Print x; y; y
End Sub
这个输出怎么是
6 6 12
6 10 10

形参和实参的问题而已:
Private Sub proc1(x As Integer, y As Integer, z As Integer)
变为
Private Sub proc1(a As Integer, b As Integer, c As Integer)
a = 3 * c
b = 2 * c
c = a + b
End Sub
就容易理解了

参数缺省是传地址,也就是子程序会改变主程序传入的参数的值,因此就出现以上的结果,如果不想改变传入参数的值,可以在参数前面用byval 前缀。